#include <iostream>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <sys/select.h>
#include <signal.h>
#include <sys/msg.h>
#include "../../macro.h"

using std::cout;
using std::cerr;
using std::endl;

constexpr static int BUF_SIZE = 1024;

struct Protocol{
    long mtype;
    char buf[BUF_SIZE];
};


int init_msg()
{
    int msgid = msgget(1000, IPC_CREAT | 0666);
    return msgid;
}

void run()
{
    struct Protocol protol{};

    // 创建 a - a1 的 
    int msgid = init_msg();    

    while(1){
        int ret = msgrcv(msgid, &protol, BUF_SIZE, 0, 0);
        ERR_CHECK(ret, -1, "msgrcv")

        cout << protol.buf;
        memset(&protol, 0, sizeof(protol));
    }
}

int main(int args, char *argv[])
{
    run();
    return 0;
}